package com.huang.lock;

import java.util.concurrent.TimeUnit;

public class deadlock {
    public static void main(String[] args) {
        Object o = new Object();
        Object o2 = new Object();

        new Thread(()->{

            synchronized (o){

                System.out.println("等待02");
                try {
                    TimeUnit.SECONDS.sleep(1);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                synchronized (o2){
                    System.out.println("02就绪。。");
                }
            }


        },"b").start();

        new Thread(()->{

            synchronized (o2){
                System.out.println("等待01");
                synchronized (o){
                    System.out.println("01就绪。。");
                }
            }


        },"a").start();
    }
}
